<template>
	<view class="my-trip">
		<u-tabs :list="navList"itemStyle="width:320rpx; height: 90rpx;"  @click="handleChoose"></u-tabs>
		<ul class="house_trip" v-if="type==1">
			<li v-for="(item,index) in tripList" :key="index">
				<dl>
					<dd>
						<p>{{item.house_title}}</p>
						<text v-if="item.sdate">{{item.sdate}} to {{item.edate}}</text>
						<text>{{item.persons}}people</text>
					</dd>
					<dt>
						<image :src="item.logo" v-if="item.logo" mode="aspectFill"></image>
					</dt>
				</dl>
				<view class="trip_ul">
					<view class="trip_item row between">
						<text>Guest name</text>
						<p>{{item.user_name}}</p>
					</view>
					<view class="trip_item row between">
						<text>Phone number</text>
						<p>{{item.user_phone}}</p>
					</view>
					<view class="trip_item row between">
						<text>Original price</text>
						<p>EGP{{item.origin_money||'0'}}</p>
					</view>
					<view class="trip_item row between">
						<text>Total date</text>
						<p>{{item.days||'0'}}days</p>
					</view>
					<view class="trip_item row between">
						<text>Service charge<text v-if="item.service_charge<=0">(today is free)</text></text>
						<p>-EGP{{item.service_charge||'0'}}</p>
					</view>
					<view class="trip_item row between">
						<text>Discount</text>
						<p>-EGP{{item.discount||'0'}}</p>
					</view>
					<view class="trip_item row between">
						<text>Total amount</text>
						<p style="color: #FF0000;">EGP{{item.total_amount||'0'}}</p>
					</view>
				</view>
				<view class="trip_state row">
					<text v-if="item.reserve_state==0" style="color: #ACACAC;">Cancelled</text>
					<text v-if="item.reserve_state==1" style="color: #13B335;">Booked</text>
					<text v-if="item.reserve_state==2" style="color: #FF3C15;">In Progress</text>
					<text v-if="item.reserve_state==3" style="color: #000000;">{{ $t('text.complete') }}</text>
					<text v-if="item.reserve_state==4" style="color: orangered;">{{ $t('text.comment') }}</text>
				</view>
			</li>
		</ul>
		<ul class="trader_ul" v-if="type==2">
			<li v-for="(item,index) in traderList" :key="index">
				<view class="row between">
					<text>Guest name</text>
					<p>{{item.user_name}}</p>
				</view>
				<view class="row between">
					<text>Living Date</text>
					<p>{{item.sdate}}</p>
				</view>
				<view class="row between">
					<text>Pay commission</text>
					<p>{{item.share_money||'0'}}EGP</p>
				</view>
				<view class="row between">
					<text>Status</text>
					<p style="color: #FF0000;">{{item.toshare==1?"Payed":"Unpaid"}}</p>
				</view>
			</li>
		</ul>
		<view class="empty" v-if="tripList.length<=0||traderList.length<=0">
			<image src="@/static/list.png" mode=""></image>
			<p>No itinerary available at the moment</p>
		</view>
		<u-loadmore v-if="hasMore&&tripList.length>0" :status="loadStatus" />
		<u-loadmore v-if="hasMore&&traderList.length>0" :status="loadStatus" />
	</view>
</template>

<script>
	import {
		agencyOrderList,
		traderOrderList
	} from '@/lib/service';
	import {
		showFailure
	} from '@/lib/helper';
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				pageNo: 1,
				pageSize: 10,
				hasMore: false,
				tripList: [],
				reserveid: "",
				info: {
					logo: "",
					title: "",
					sdate: "",
					edate: ""
				},
				type:1,
				traderList:[],
				navList:[{
					name:'house owner order',
					type:1
				},{
					name:'trader order',
					type:2
				}]
			}
		},
		onShow() {
			let _this = this;
			_this.pageNo = 1;
			_this.tripList = [];
			_this.loadData();

		},
		onPullDownRefresh() {
			this.pageNo = 1;
			if(this.type==1){
				this.tripList = [];
				this.loadData(true);
			}else{
				this.traderList = [];
				this.traderData(true);
			}
			
			
			setTimeout(()=>{
				uni.stopPullDownRefresh();
			},1500)
		},
		onReachBottom() {
			if (this.hasMore&&this.type==1) {
				this.pageNo = this.pageNo + 1;
				this.loadData();
			}else if (this.hasMore&&this.type==2) {
				this.pageNo = this.pageNo + 1;
				this.traderData();
			}
		},
		methods: {
			
			loadData(isReset) {
				this.loadStatus = 'loading';
				let obj = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				}
				agencyOrderList(obj).then((res) => {
						uni.hideLoading();
						this.loadStatus = 'no-more';
						this.hasMore = res.data.hasMore;
						if (isReset) {
							this.tripList = res.data.records;
						} else {
							this.tripList = this.tripList.concat(res.data.records);
						}
					})
					.catch((res) => {
						this.loadStatus = 'no-more';
						uni.hideLoading();
						showFailure();
					});
			},
			traderData(isReset){
				this.loadStatus = 'loading';
				let obj = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				}
				traderOrderList(obj).then((res) => {
						uni.hideLoading();
						this.loadStatus = 'no-more';
						this.hasMore = res.data.hasMore;
						if (isReset) {
							this.traderList = res.data.records;
						} else {
							this.traderList = this.traderList.concat(res.data.records);
						}
					})
					.catch((res) => {
						this.loadStatus = 'no-more';
						uni.hideLoading();
						showFailure();
					});
			},
			handleChoose(e){
				this.type = e.type;
				if(this.type==1){
					this.pageNo = 1;
					this.tripList = [];
					this.loadData();
				}else{
					this.pageNo = 1;
					this.traderList = [];
					this.traderData();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.empty {
		text-align: center;
		margin-top: 15vh;

		image {
			width: 376rpx;
			height: 376rpx;
		}

		p {
			font-size: 28rpx;
			color: #999999;
		}
	}
	.my-trip{
		width: 100%;
		min-height: 100%;
		background: #FAFBFF;
		position: absolute;
	}

	.house_trip {
		padding: 30rpx;
		li {
			background: #ffffff;
			border-radius: 10rpx;
			padding: 20rpx;
			position: relative;
			margin-bottom: 24rpx;
			dl {
				display: flex;
				justify-content:space-between;
				border-bottom: 0.5px solid #E1E1E1;
				padding-bottom: 14rpx;
				dt {
					image {
						width: 249rpx;
						height: 188rpx;
						background: #eeeeee;
						border-radius: 12rpx;
					}
				}

				dd {
					padding-right: 16rpx;
					p {
						font-family: Microsoft YaHei UI;
						font-weight: bold;
						font-size: 26rpx;
						color: #333333;
					}

					text {
						font-family: Microsoft YaHei UI;
						font-weight: 400;
						font-size: 26rpx;
						color: #666666;
						display: block;
						margin-top: 16rpx;
					}
				}
			}
           .trip_ul{
           	padding-bottom: 20rpx;
           	border-bottom: 0.5px solid #E1E1E1;
           	.trip_item{
           		margin-top: 20rpx;
           		font-size: 26rpx;
           		text{
           			display: inline-block;
           			color:#999999;
           		}
           	}
           }
			.trip_state {
				margin-top:12rpx;
				justify-content: space-between;

				text {
					color: #13B335;
					font-weight: 400;
					font-size: 26rpx;
				}
			}
		}
	}
	.trader_ul{
		padding: 30rpx;
		li {
			background: #ffffff;
			border-radius: 10rpx;
			padding: 20rpx;
			margin-bottom: 24rpx;
			view{
				margin-bottom: 20rpx;
				font-size: 26rpx;
				text{
					color: #999999;
				}
			}
			}
	}


</style>